$(function () {
    $("#btn_submit").click(function () {
        var user_name = document.getElementById("user_name");
        var password1 = document.getElementById("Password1");
        var password2 = document.getElementById("Password2");
        var flag = 1;
        if (user_name.value == "") {
            alert("用户名不能为空!");
            flag = 0;
        }
        else {
            if (password1.value == "") {
                alert("密码不能为空!");
                flag = 0;
            } else {
                if (password2.value == "") {
                    alert("请确认密码!");
                    flag = 0;
                } else {
                    if (password1.value != password2.value) {
                        alert("两次输入的密码不一致!");
                        flag = 0;
                    }
                }
            }
        }
        if (flag == 1) {
            $.get(
                "/RegisterServlet",
                {user_name:user_name.value,password1:password1.value},
                function (data) {
                    var exit = data.exit;
                    if (exit == 1) {
                        alert("该用户名已存在");
                    }
                    else {
                        alert("注册成功，点击确认后返回登陆页面");
                        window.location.href = "login.html";
                    }
                }
            );
        }
    });
});
